<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src='https://unpkg.com/vue@next'></script>
    <div id="app">
        <todo-item @click="clickCom" @submit="subCom"></todo-item>
    </div>

    <script>
        const vueOpt = {
            methods:{
                clickCom(){
                    console.log('click event');
                },
                subCom(){
                    console.log('submit event');
                }
            }
        }

        const app = Vue.createApp(vueOpt);

        app.component('todo-item', {
            data(){
                return {

                }
            },
            // 会在触发时，检测触发传参是否满足验证规则，并不会在监听函数一侧校验规则
            emits:{
                // 没有验证
                click: null,

                submit: ({email, password}) => {
                    console.log('----1');
                    if(email && password){
                        return true;
                    } else {
                        console.warn("Invalid submit event payload");
                        return false;
                    }
                }
            },
            template: 
            `
                <div>
                    <button type="button" @click="clickEvent">1111</button>
                    <button type="button" @click="submitEvent">2222</button>
                </div>
            `,

            methods: {
                clickEvent(){
                    this.$emit('click');
                },

                submitEvent(){
                    // 会在该侧，检测触发传参是否满足验证规则
                    this.$emit('submit', 'a', 'b');
                }
            }
        });

        app.mount('#app');
    </script>
</body>
</html>
